﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Smled
{
    public partial class ResizeDialog : Form
    {
        public ResizeDialog()
        {
            InitializeComponent();
            txtW.Validating += new CancelEventHandler(txtW_Validating);
            txtH.Validating += new CancelEventHandler(txtH_Validating);
        }

        void txtH_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                int a = Int32.Parse(txtH.Text);
                if (a < 1) a = 1;
                if (a > 500) a = 500;
                txtH.Text = a.ToString();
            }
            catch
            {
                txtH.Text = "1";
            }
        }

        void txtW_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                int a = Int32.Parse(txtW.Text);
                if (a < 1) a = 1;
                if (a > 500) a = 500;
                txtW.Text = a.ToString();
            }
            catch
            {
                txtW.Text = "1";
            }
        }

        public ContentAlignment CropAlignment
        {
            get
            {
                if (rbU.Checked) return ContentAlignment.TopCenter;
                if (rbUR.Checked) return ContentAlignment.TopRight;
                if (rbL.Checked) return ContentAlignment.MiddleLeft;
                if (rbC.Checked) return ContentAlignment.MiddleCenter;
                if (rbR.Checked) return ContentAlignment.MiddleRight;
                if (rbDL.Checked) return ContentAlignment.BottomLeft;
                if (rbD.Checked) return ContentAlignment.BottomCenter;
                if (rbDR.Checked) return ContentAlignment.BottomRight;
                return ContentAlignment.TopLeft;
            }
        }

        public int MapWidth
        {
            get
            {
                int a = Int32.Parse(txtW.Text);
                if (a < 1) a = 1;
                if (a > 500) a = 500;
                return a;
            }

            set
            {
                txtW.Text = value.ToString();
            }
        }

        public int MapHeight
        {
            get
            {
                int a = Int32.Parse(txtH.Text);
                if (a < 1) a = 1;
                if (a > 500) a = 500;
                return a;
            }

            set
            {
                txtH.Text = value.ToString();
            }
        }

        private void cmdOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
